package com.shopping.controller.front;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.shopping.commons.controller.BaseController;
import com.shopping.commons.response.MessageResp;
import com.shopping.commons.util.CommonCode;
import com.shopping.param.OrderParam;
import com.shopping.response.UserResp;
import com.shopping.service.IOrderService;

/**
 * 用户的   Conroller
 * @author Administrator
 *
 */
@Controller
@RequestMapping("front/order") 
public class FrontOrderController extends BaseController{

	@Autowired
	private IOrderService orderService;
	
	/**
	 * 增加某个用户
	 * @param request
	 * @param param
	 * @return
	 */
	@RequestMapping("insert")
	@ResponseBody  ///这个是吧MessageResp转成  json 的注解   普遍就是   对应  ajax 的请求    
	public MessageResp insert(HttpServletRequest request,OrderParam param){
		MessageResp resp=new MessageResp();
		UserResp retUser=this.getUser(request);
		if(retUser==null){
			resp.setCode(CommonCode.FAIL);
			resp.setMsg("下订失败，请先登录");
			return resp;
		}
		param.setUserid(retUser.getUserid());
		return orderService.addOrderAndDetails(param);
	}
	
}
